package com.yuandian.bpm.bi.modules.quartz.util.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 * 模块名称：redis监听通道数据（订阅端）
 * 开发人员：LSH
 * 日        期：2022/09/14
 */
@Configuration
public class RedisSubListenerConfig {
	
	/**
	 * 消息适配器
	 * @return
	 */
	@Bean
	public MessageListenerAdapter listenerAdapter(){
		return new MessageListenerAdapter(new RedisReceiver(), "receiveMessage");
	}
	
	/**
	 * 定义消息监听容器
	 * @param connectionFactory
	 * @param listenerAdapter
	 * @return
	 */
	@Bean
	public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
		RedisMessageListenerContainer listenerContainer = new RedisMessageListenerContainer();
		listenerContainer.setConnectionFactory(connectionFactory);
		listenerContainer.addMessageListener(listenerAdapter, new PatternTopic(Constants.Redis.QUEUE_PROBE_TASK));
		return listenerContainer;
	}
}
